<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <a lay-href="">主页</a>
        <a><cite>关于我们</cite></a>
        <a><cite>关于我们</cite></a>
    </div>
</div>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="layadmin-userfront-formlist">
            <div class="layui-fluid">
                <div class="layui-card">
                    <div class="layui-card-body">
                        <table class="layui-hide" id="table-instance" lay-filter="table-instance"></table>
                        <script type="text/html" id="imgTpl">
                            <img style="display: inline-block; width: 50%; height: 100%;" src={ { d.avatar }}>
                        </script>
                        <script type="text/html" id="table-useradmin-webuser">
                            <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
                        </script>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['layedit', 'admin', 'upload', 'laydate', 'useradmin', 'table', 'form'], function() {
        var $ = layui.$,
            admin = layui.admin,
            setter = layui.setter,
            view = layui.view,
            table = layui.table,
            form = layui.form,
            leyer = layui.leyer,
            upload = layui.upload,
            laydate = layui.laydate,
            layedit = layui.layedit;

        form.render(null, 'layadmin-userfront-formlist');
        //监听搜索
        form.on('submit(LAY-user-front-search)', function(data) {
            var field = data.field;
            //执行重载
            table.reload('table-instance', {
                where: field
            });
        });

        table.render({
            elem: "#table-instance",
            url: setter.request.baseUrl + "/ours/admin/list",
            method: "get",
            // toolbar: '#toolbarDemo', //开启头部工具栏，并为其绑定左侧模板  
            headers: {
                token: layui.data("layuiAdmin").token
            },
            response: {
                statusName: "code",
                statusCode: 0,
                msgName: "msg",
                countName: "count",
                dataName: "list",
            },
            where: {
                typeId: 1
            },
            cols: [
                [{
                    align: 'center',
                    field: "id",
                    width: "7%",
                    sort: true
                }, {
                    align: 'center',
                    field: "companyInfo",
                    width: "15%",
                    title: "走进博斯奥"
                }, {
                    align: 'center',
                    field: "videoUrl",
                    width: "9%",
                    templet: "#video",
                    title: "视频链接"
                }, {
                    align: 'center',
                    field: "brandInfo",
                    width: "15%",
                    title: "品牌简介"
                }, {
                    align: 'center',
                    field: "mission",
                    width: "20%",
                    title: "使命"
                }, {
                    align: 'center',
                    field: "coreValue",
                    width: "15%",
                    title: "核心价值观"
                }, {
                    align: 'center',
                    field: "bgImg",
                    width: "9.5%",
                    templet: "#img",
                    title: "企业文化背景图"
                }, {
                    align: 'center',
                    title: "操作",
                    toolbar: "#table-useradmin-webuser" //删除
                }]
            ],
            page: true, //分页
        });

        $('.layui-btn.layuiadmin-btn-useradmin').on('click', function() {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        $(document).on("click", ".table-check-img", function(e) {
            var json = {
                title: "审核图片",
                id: 0,
                start: 0,
                data: [{
                    alt: "",
                    pid: 1,
                    src: $(e.target).data("img"),
                    //原图地址
                    thumb: "",
                }, ],
            };
            console.log(json)
            if (json.data[0].src == null) {
                layer.msg("暂无图片", {
                    offset: "15px",
                    icon: "2",
                    time: 1000
                })
            } else {
                var result = json.data[0].src.split(",");
                var j = new Array;
                for (var i = 0; i < result.length; i++) {
                    let json = {
                        "src": result[i]
                    }
                    j[i] = json;
                }
                layer.photos({
                    photos: {
                        "data": j
                    },
                    anim: 1,
                });
            }
        });
        $(document).on("click", ".table-check-video", function(e) {
                e.stopPropagation()
                var loadstr = '<video width="100%" height="100%" align=" center" controls="controls" autobuffer="autobuffer"  autoplay="autoplay" loop="loop"><source src="https://demoee.oss-cn-shanghai.aliyuncs.com/biosso/47e4dd9bcca044288ee1d73e094c38ee"></source></video>'
                off = true;
                if (off) {
                    flag = false;
                    layer.open({
                        type: 1,
                        title: '播放视频',
                        content: loadstr,
                        offset: ['25%', '25%'], //设置位移
                        cancel: function() {}
                    });
                }
            })
            // 修改模块
        table.on("tool(table-instance)", function(obj) {
            var data = obj.data;
            if (obj.event === "edit") {
                admin.popup({
                    title: "编辑用户",
                    area: ["600px", "600px"],
                    success: function(layero, index) {
                        view(this.id)
                            .render("user/administrators/technologyform", data)
                            .done(function() {
                                let _data = data;
                                form.render(null, "layuiadmin-form-admin");
                                laydate.render({
                                    elem: '#date'
                                });
                                laydate.render({
                                    elem: '#date1'
                                });
                                var releaseTime = layui.util.toDateString(new Date(_data.releaseTime * 1000).getTime(), "yyyy-MM-dd");
                                laydate.render({
                                    elem: '#date',
                                    value: releaseTime,
                                    isInitValue: true
                                });

                                var endTime = layui.util.toDateString(new Date(_data.endTime * 1000).getTime(), "yyyy-MM-dd");
                                laydate.render({
                                    elem: '#date1',
                                    value: endTime,
                                    isInitValue: true
                                });

                                layedit.set({
                                    uploadImage: {
                                        url: setter.request.baseUrl + '/upload/admin/file', //接口url
                                        type: 'post' //默认post
                                    }
                                });

                                var aa = layedit.build('demo'); //富文本
                                form.on("submit(LAY-user-front-submit)", function(data) {

                                    var field = data.field;


                                    var aahtml = layedit.getContent(aa);
                                    field.detail = aahtml
                                    editUserHandle(Object.assign(_data, field));

                                    layer.close(index);
                                });
                            });
                    },
                });
            }
        });

        //修改编辑
        function editUserHandle(params) {
            admin.req({
                url: setter.request.baseUrl + "/ours/admin/save",
                data: JSON.stringify(params),
                type: "post",
                dataType: "json",
                contentType: "application/json",
                done: function(res) {
                    layui.table.reload("table-instance");
                },
            });
        }

    });
</script>
<script type="text/html" id="img">
    <button type="button" class="layui-btn layui-btn-xs table-check-img" data-img="{{d.bgImg}}">查看图片</button>
</script>
<script type="text/html" id="video">
    <button type="button" class="layui-btn layui-btn-xs table-check-video" data-img="{{d.videoUrl}}">查看视频</button>
</script>